﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using WebApplication1.Business;

namespace WebApplication1
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        ImagesBusiness ib = new ImagesBusiness();
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dtb = ib.GetImage(Session["User"].ToString());
            DataList1.DataSource = dtb;
            DataList1.DataBind();
        }

        protected void ButtonUpload_Click(object sender, EventArgs e)
        {

            bool flag = ib.CheckImg(FileUpload1.FileName,Session["user"].ToString());
            string serverPath = Server.MapPath(".");
            string urls = serverPath + "/OrderImages/" + FileUpload1.FileName;
            string fileEx = System.IO.Path.GetExtension(FileUpload1.FileName);
                
            if (FileUpload1.FileContent.Length > 0)
            {
                if (fileEx != ".JPG" && fileEx != ".JPEG" && fileEx != ".jpg" && fileEx != ".jpeg")
                {
                    App.showMessage(this.Page, GetType(), "JPG or JPEG !", false);
                }
                else
                {
                    if (flag)
                    {
                        App.showMessage(this.Page, GetType(), "File was existed !", false);
                    }
                    else
                    {
                        FileUpload1.SaveAs(urls);
                        ib.UploadImages(FileUpload1.FileName, Session["user"].ToString());
                        App.showMessage(this.Page, GetType(), "Upload successful !", false);
                        Response.Redirect("Upload.aspx");
                    }
                   
                }

            }
            else
            {
                App.showMessage(this.Page, GetType(), "Please choose a file !", false);
            }
                      
        }
    }
}
